package com.miyue.stepdemo

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.viewinterop.AndroidView

class StepComposeView : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            Surface(
                modifier = Modifier.fillMaxSize(),
                color = MaterialTheme.colorScheme.background
            ) {
                CustomView()
            }
        }
    }
}

@Composable
fun CustomView() {
    AndroidView(
        modifier = Modifier.fillMaxSize(), // Occupy the max size in the Compose UI tree
        factory = { context ->
            // Creates view
            StepView(context).apply {
                setText("第一步")
                setTextSize(30f)
                setStyle(StepView.STYLE_SELECTED)
                setType(StepView.TYPE_START)
            }
        },
        update = { view ->
            // 视图已膨胀或此块中读取的状态已更新
            // 如有必要，在此处添加逻辑
            // 由于selectedItem在此处阅读，AndroidView将重新组合
            // 每当状态发生变化时
            // 撰写示例->查看通信

            // 更新样式
            view.setText("第二步")
        }
    )
}
